package com.student.jps.service.impl;

import com.student.jps.dao.StudentDao;
import com.student.jps.entity.Student;
import com.student.jps.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;


    @Override
    public Page<Student> getList(Pageable pageable) {
        return studentDao.findAll(pageable);
    }

    @Override
    public Student insert(Student student) {
        return studentDao.saveAndFlush(student);
    }

    @Override
    public Student update(Student student) {
        return studentDao.saveAndFlush(student);
    }

    @Override
    public List<Student> findByNameLike(String name) {
        return studentDao.findByNameLike(name);
    }

    @Override
    public Optional<Student> getById(Integer id) {
        return studentDao.findById(id);
    }

    @Override
    public Page<Student> findBySexLike( String sex,Pageable pageable) {
        return (Page<Student>) studentDao.findBySexLike(sex,pageable);
    }

    @Override
    public void delete(Student student) {
        studentDao.delete(student);
    }


}
